﻿@model Model.AppUserList
@{
    ViewBag.Title = "GoodsInfoManage";
    Layout = "~/Views/Shared/_JQBaseLayOut.cshtml";
}
@using Model

@section JQscriptSection{
    <script type="text/javascript">
        $(document).ready(function () {
            $('#lookupType').combobox('setValue', '');
            $('#sSelectIsShow').combobox('setValue', '');

            InitGrid();

        });

        HandleDom.ClassTriggerClick("icon-edit", function () {
            var row = HandleData.GetDataGridSelected("dg");
            edit(row);
        });
        HandleDom.ClassTriggerClick("icon-alledit", function () {
            var row = HandleData.GetDataGridSelected("dg");
            allEdit(row);
        });
        //编辑
        function edit(data) {
            HandleData.ClearForm('location');
            HandleDialog.OpenDialog(data, 'dlg', '编辑货位信息', function () {
                $('#CustomCELLNO').combobox('setValue', '0');
                if (data != "") {
                    $('#p1').dialog('open').dialog('setTitle', '修改商品资料信息');
                    $("#txtGOODSCODE").val(data.GOODSCODE);
                    $("#txtGOODSNAME").val(data.GOODSNAME);
                    $('#lookupTypes').combobox('setValue', data.CELLNO);
                    $('#selectIsShow').combobox('setValue', data.ISSHOW);

                    $("#txtGoodsJhl").val(data.PKGLOSSQTY);
                    $("#txtSaleStorkQTY").val(data.SALESTOCKQTY);
                    $('#hiddenGoodsCode').val(data.GOODSCODE);
                    $("#txtRuleClass").val(data.RULECLASS);
                } else {
                    rows = grid.datagrid('getSelections');
                    $('#p1').dialog('open').dialog('setTitle', '修改商品资料信息');
                    $("#txtGOODSCODE").val(rows[0].GOODSCODE);
                    $("#txtGOODSNAME").val(rows[0].GOODSNAME);
                    $('#lookupTypes').combobox('setValue', rows[0].CELLNO);
                    $("#txtGoodsJhl").val(rows[0].PKGLOSSQTY);
                    $("#txtSaleStorkQTY").val(rows[0].SALESTOCKQTY);
                    $('#hiddenGoodsCode').val(rows[0].GOODSCODE);
                    $('#selectIsShow').combobox('setValue', data.ISSHOW);
                    $("#txtRuleClass").val(data.RULECLASS);
                }


                $("#txtGOODSCODE").attr("disabled", "disabled");
                $("#txtGOODSNAME").attr("disabled", "disabled");
                $('#lookupTypes').combobox('disable');

            });
        }
        //编辑
        function allEdit(data) {
            HandleData.ClearForm('location');
            HandleDialog.OpenDialog(data, 'p2', '编辑货位信息', function () {
                $('#CustomCELLNO_batch').combobox('setValue', '0');

            });
        }

        function saveData() {
            HandleRequest.submitForm('location', '@Url.Action("SaveData", "GoodsInfoManage")', function (data) {
                eval('data=' + data);
                if (data.success == true) {
                    layer.alert('执行成功!', 9);
                    InitGrid();
                    HandleDialog.CloseDialog('dlg');
                } else {
                    layer.msg(data.msg, 1);
                }
            });
        }

        function saveDataAll() {
            var goodsCodes = "";
            var rows = $('#dg').datagrid('getSelections');
            for (var i = 0; i < rows.length; i++) {
                goodsCodes = goodsCodes + rows[i].GOODSCODE + ",";
            }
            $('#hiddenGoodsCodeBatch').val(goodsCodes);
            HandleRequest.submitForm('location_batch', '@Url.Action("SaveDataBatch", "GoodsInfoManage")', function (data) {
                eval('data=' + data);
                if (data.success == true) {
                    layer.alert('执行成功!', 9);
                    InitGrid();
                    HandleDialog.CloseDialog('dlg');
                } else {
                    layer.msg(data.msg, 1);
                }
            });
        }

        function InitGrid() {
            var txtGoodsCode = $('#txtGoodsCode').val();
            var txtGoodsName = $('#txtGoodsName').val();
            var lookupType = $('#lookupType').combobox('getValue');

            var sSelectIsShow = $('#sSelectIsShow').combobox('getValue');
            var QuRuleClass = $('#QuRuleClass').val();
            queryParams = {
                goodsCode: txtGoodsCode,
                goodsName: txtGoodsName,
                lookup: lookupType,
                selectIsShow: sSelectIsShow,
                QuRuleClass: QuRuleClass
            }
            HandleData.InitDataGrid('dg', '/GoodsInfoManage/InitJsonResult', 'toolbar', queryParams, 'GOODSID', false, function (data) {
                $.each(data.rows, function (index, item) {
                    console.log(item.ISSHOW);
                    if (item.ISSHOW == "0") {
                        return 'background-color:red;';
                    }
                });
            },
                function (rowIndex, rowData) {//双击
                    edit(rowData);
                });
        }
    </script>
}

<body style="background-color: ButtonFace; font-size: 17px">
    <div class="easyui-panel" title="查询条件" style="height: 100px; padding: 5px; background: #fafafa; width: 1700px;">
        <form id="query" method="post">
            <table>
                <tr>
                    <td>商品编号:
                    </td>
                    <td>
                        <input type="hidden" id="selectList" name="selectList" />
                        <input id="txtGoodsCode" name="txtGoodsCode" style="width: 154px" />
                    </td>
                    <td>商品名称:
                    </td>
                    <td>
                        <input id="txtGoodsName" name="txtGoodsName" style="width: 154px" />
                    </td>
                    <td>库位名称:
                    </td>
                    <td>
                        <input id="lookupType" class="easyui-combobox" name="lookupType" style="width: 155px;" data-options="required:true,valueField:'FIELDVALUE',textField:'LOOKUP',url:'@Url.Action("GetGoodsLookUpInfo", "GoodsInfoManage", new { isDefault = true, defaultValue = "全部" })',editable:false">
                    </td>

                    <td>是否在BOM中显示:
                    </td>
                    <td>
                        <select id="sSelectIsShow" class="easyui-combobox" name="sSelectIsShow" style="width: 100px;">
                            <option value="">全部</option>
                            <option value="1">显示</option>
                            <option value="0">隐藏</option>
                        </select>
                    </td>
                     
                    <td>
                        <a id="btnSerach" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-search'" onclick="InitGrid();">查询</a>
                    </td> 
                </tr>
                <tr>
                    <td>可售期规则类别:</td>
                    <td>
                        <input id="QuRuleClass" name="QuRuleClass" style="width: 100px;" />
                    </td>
                </tr>
            </table>
        </form>
    </div>
    <div style="min-height: 720px; width: 1700px;">
        <table id="dg" title="商品信息" style="min-height: 600px;">
            <thead>
                <tr>
                    <th data-options="field:'ck',checkbox:true"></th>
                    <th data-options="field:'GOODSID',width:30">GOODSID</th>
                    <th data-options="field:'GOODSCODE',width:50">货号</th>
                    <th data-options="field:'GOODSNAME',width:50">品名</th>
                    <th data-options="field:'PKGLOSSQTY',width:50">净含量</th>
                    <th data-options="field:'SALESTOCKQTY',width:80">可销售库存占比</th>
                    <th data-options="field:'RULECLASS',width:50">可售期规则类别</th>
                    <th data-options="field:'LOOKUP',width:50">库位</th>
                    <th data-options="field:'DLOOKUP',width:50">自定义库位</th> 
                </tr>
            </thead>
        </table>
    </div>

    <div id="dlg" class="easyui-dialog" style="width: 620px; height: 200px; top: 300px; left: 400px; padding: 2px"
        data-options="closed:true,buttons:'#dlg-buttons',modal:true">
        <form id="location" method="post">
            <table>
                <tr>
                    <td>商品编码:
                    </td>
                    <td>
                        <input id="hiddenGoodsCode" name="hiddenGoodsCode" type="hidden" />
                        <input id="txtGOODSCODE" name="txtGOODSCODE" maxlength="30" style="width: 154px;" />
                    </td>
                    <td>商品名称:
                    </td>
                    <td colspan="2">
                        <input id="txtGOODSNAME" name="txtGOODSNAME" style="width: 184px" />
                    </td>
                </tr>
                <tr>
                    <td>库位:
                    </td>
                    <td>
                        <input id="lookupTypes" class="easyui-combobox" name="lookupTypes" style="width: 155px;" data-options="required:true,valueField:'FIELDVALUE',textField:'LOOKUP',url:'@Url.Action("GetGoodsLookUpInfo", "GoodsInfoManage", new { isDefault = true, defaultValue = "全部" })',editable:false">
                    </td>
                    <td>自定义库位:
                    </td>
                    <td colspan="2">
                        <input id="CustomCELLNO" class="easyui-combobox" name="CustomCELLNO" style="width: 184px;" data-options="required:true,valueField:'FIELDVALUE',textField:'LOOKUP',url:'@Url.Action("GetGoodsCustomLookUpInfo", "GoodsInfoManage", new { isDefault = true, defaultValue = "全部" })',editable:false">
                    </td>
                </tr>
                <tr>
                    <td>净含量:
                    </td>
                    <td>
                        <input id="txtGoodsJhl" name="txtGoodsJhl" class="easyui-validatebox" style="width: 154px" validtype="floatOrInt['#txtGoodsJhl']" />
                    </td>
                    <td>可售库存占比:
                    </td>
                    <td>
                        <input id="txtSaleStorkQTY" name="txtSaleStorkQTY" class="easyui-validatebox" style="width: 184px" validtype="forIntToOneHundred['#txtSaleStorkQTY']" />
                    </td>
                </tr>
                <tr>
                    <td>是否在BOM中显示:
                    </td>
                    <td>
                        <select id="selectIsShow" class="easyui-combobox" name="selectIsShow" style="width: 154px;">
                            <option value="1">显示</option>
                            <option value="0">隐藏</option>
                        </select>
                    </td>
                    <td>可售期规则类别</td>
                    <td>
                        <input id="txtRuleClass" name="txtRuleClass" class="easyui-validatebox" style="width: 184px"  />
                    </td>
                </tr>
                <tr>
                    <td></td>
                    <td>
                        <a id="btnSave" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-save'" onclick="saveData()">保存</a>
                    </td>
                </tr>
                
            </table>
        </form>
    </div>
    <div id="p2" class="easyui-dialog" style="width: 620px; height: 200px; top: 300px; left: 400px; padding: 2px"
        data-options="closed:true,buttons:'#dlg-buttons',modal:true">
        <form id="location_batch" method="post">
            <table>
                <tr>

                    <td>自定义库位:
                    </td>
                    <td colspan="2">
                        <input id="hiddenGoodsCodeBatch" name="hiddenGoodsCodeBatch" type="hidden" />
                        <input id="CustomCELLNO_batch" class="easyui-combobox" name="CustomCELLNO_batch" style="width: 155px;" data-options="required:true,valueField:'FIELDVALUE',textField:'LOOKUP',url:'@Url.Action("GetGoodsCustomLookUpInfo", "GoodsInfoManage", new { isDefault = true, defaultValue = "全部" })',editable:false">
                    </td>
                </tr>

                <tr>
                    <td></td>
                    <td>
                        <a id="btnSave_batch" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-save'" onclick="saveDataAll()">确定</a>
                    </td>
                </tr>
            </table>
        </form>
    </div>
    @Html.Partial("~/Views/Shared/_PartialToolbar.cshtml", new Toolbar
{
    GridName = "dg",
    GridType = "datagrid",
    ToolbarName = "toolbar",
    FunctionModule = new Dictionary<string, List<FunctionModule>>()
    {
        {"Function",new List<FunctionModule>()
            {
              new FunctionModule(){Name = "Add",IsEnable =false },
              new FunctionModule(){Name = "Edit",IsEnable =true },
              new FunctionModule(){Name = "Remove",IsEnable =false },
              new FunctionModule(){Name = "Reload",IsEnable =false },
              new FunctionModule(){Name = "Collapse",IsEnable =false },
              new FunctionModule(){Name = "Exporter",IsEnable =true },
              new FunctionModule(){Name = "AllEdit",IsEnable =true },
              
              
            }
        }
    }
})

</body>


